package 并查集;

public class 等式方程的可满足性 {

    public boolean equationsPossible(String[] equations) {
        UF uf = new UF(26);
        for (String equation : equations) {
            if (equation.charAt(1)=='='){
                char x = equation.charAt(0);
                char y = equation.charAt(3);
                uf.union(x-'a',y-'a');
            }
        }
        for (String equation : equations) {
            if (equation.charAt(1)=='!'){
                char x = equation.charAt(0);
                char y = equation.charAt(3);
                if (uf.connected(x-'a',y-'a'))
                     return false;
            }
        }
        return true;
    }
}
